package org.fglxy.mockserver.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.fglxy.mockserver.util.IdFactoryUtils;
import org.fglxy.mockserver.util.WebUtils;
import org.slf4j.MDC;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@Order(1)
@Aspect
@Component
public class RequestLogMDCAspect {
	
	@Around("execution(* org.fglxy.mockserver.controller..*(..)) and "
			+ "@annotation(org.springframework.web.bind.annotation.RequestMapping)")
	public Object requestAroundAspect(ProceedingJoinPoint point) throws Throwable {
		MDC.put("requestId", IdFactoryUtils.generateId());
		MDC.put("clientIp", WebUtils.getIpAddr());
		return point.proceed();
	}
}
